import QtQuick 1.0

Rectangle {
    id: pg


    property alias colorPage: pg.color
    property color colorBorder
    property string prevPage: ""

    function closePage(_prevPage) {
        if( _prevPage !== "" ) {
            pg.prevPage = _prevPage
            pg.state = "hidden"
        } else if( pg.prevPage ) {
            pg.state = "hidden"
        }
    }

    height: mytheme.displayHeight
    width: mytheme.displayWidth
    anchors.fill: parent

    border.color: colorBorder

    radius: mytheme.radiusMainWin

    clip: true

    Image {
        id: background
        anchors.fill: parent
        source: "qrc:/qml/images/wp1.png"
        opacity: 0.7
    }

    /*------------*/
    transform: [
        Rotation {
            id: plateRotation
            angle: 0
            axis { x: 0; y: 1; z: 0 }
            origin.x: -100
            origin.y: 0 //50
        }
    ]

    property int _tAnimScale: 100
    property int _tAnimAngle: 200

    state: "hidden"
    states: [
        State {
            name: "hidden"
            PropertyChanges { target: plateRotation; angle: -90 }
            PropertyChanges { target: pg; scale: 0.96 }
            PropertyChanges { target: pg; opacity: 0 }
        },
        State {
            name: "visible"
            PropertyChanges { target: plateRotation; angle: 0 }
            PropertyChanges { target: pg; scale: 1 }
            PropertyChanges { target: pg; opacity: 1 }
        }
    ]

    transitions: [
        Transition {
            from: "hidden"; to: "visible"
            ParallelAnimation {
                SequentialAnimation {
                    PauseAnimation { duration: _tAnimScale*0.4 }
                    NumberAnimation { property: "opacity"; duration: _tAnimAngle; easing.type: Easing.InOutQuad }
                }
                SequentialAnimation {
                    RotationAnimation{ properties: "angle"; from: 90; to: 0; duration: _tAnimAngle; easing.type: Easing.OutCubic }
                    NumberAnimation { property: "scale"; duration: _tAnimScale; easing.type: Easing.InOutQuad }
                }
            }
        },
        Transition {
            from: "visible"; to: "hidden"
            ParallelAnimation {
                SequentialAnimation {
                    PauseAnimation { duration: _tAnimScale*0.4 }
                    NumberAnimation { property: "opacity"; duration: _tAnimAngle; easing.type: Easing.InOutQuad }
                }
                SequentialAnimation {
                    NumberAnimation { property: "scale"; duration: _tAnimScale; easing.type: Easing.InOutQuad }
                    RotationAnimation { properties: "angle"; duration: _tAnimAngle; easing.type: Easing.OutCubic }
                    ScriptAction { script: main.loadPage = prevPage }
                }
            }
        }
    ]

}
